export type CapitalzeString<S extends string> = `${Capitalize<S>}`


export type FirstChar<S extends string> = S extends `${infer R}${string}` ? R : never
type P2 = FirstChar<'hujiang'>

export type LastChar<S extends string, F = never> = S extends `${infer L}${infer R}` ? LastChar<R, L> : F
type T3 = LastChar<'hujiang'>

export type StringToTuple<T extends string, F extends any[] = []> =
  T extends `${infer L}${infer R}`
  ? StringToTuple<R, [...F, L]>
  : F

type T4 = StringToTuple<'hujiang'>

export type TupleToString<T extends any[], F extends string = ''> = T extends [infer L , ...infer R]
  ? TupleToString<R, `${F}${L extends string ? L : ''}`>
  : F
type T5 = TupleToString<['h','u', 'j','i','a','n','g']>

export type RepeatString<T extends string, C extends number, F extends any[] = [], R extends string = ''> = F['length'] extends C 
     ? R
     :  RepeatString<T, C, [...F, null], `${R}${T}`>
type T6 = RepeatString<"hu", 3>;

export type SplitString<T extends string, S extends string, SR extends string = '', F extends any[] = []> = T extends `${infer L}${infer R}` 
  ? L extends S 
    ? SplitString<R, S, '', [...F, SR]>
    : SplitString<R, S, `${SR}${L}`, F>
  : [...F, SR]
type A1 = SplitString<"handle-open-flag", "-">;

export type LengthOfString<T extends string, F extends any[] = []> = T extends `${infer L}${infer R}`
  ? LengthOfString<R, [...F, L]>
  : F['length']

type B = LengthOfString<"BFE.dev">; // 7

export type KebabCase<T extends string, F extends string = ''> = T extends `${infer L}${infer R}`
  ? F extends '' 
    ? KebabCase<R, `${Lowercase<L>}`>
    : L extends Uppercase<L> 
     ?  KebabCase<R, `${F}-${Lowercase<L>}`>
     :  KebabCase<R, `${F}${L}`>
  : F
type C = KebabCase<"HandleOpenFlag">;


export type CamelCase<T extends string, F extends string = ''> = T extends `${infer L}-${infer R}`
  ? CamelCase<R, `${F}${Capitalize<L>}`>
  : `${F}${Capitalize<T>}`
type D = CamelCase<"handle-open-flag">; 


export type ComponentEmitsType<T extends { [key:string]: any}> = {
  [K in keyof T  as `on${K extends string ? CamelCase<K> : ''}`] : T[K] extends ((...args: infer R) => void) ? (...args: R) => void : T[K]
}
type a1 = {
  "handle-open": (flag: boolean) => true;
  "preview-item": (data: { item: any; index: number }) => true;
  "close-item": (data: { item: any; index: number }) => true;
};

type a2 = ComponentEmitsType<a1>;